export default {
  data() {
    var checkRentMode = (rule, value, callback) => {
      // if ((value == 1 && this.form.rentPrice == "") && (this.form.sellMode == 1 && this.form.sellingPrice == "")) {
      //   callback(new Error("请输入租金价格或出售价格"));
      // }
      if(!value){
        callback(new Error("请选择租金方式"));
      }else if (value == 1 && this.form.rentPrice == "") {
        this.$refs.form.validateField("sellMode")
        callback(new Error("请输入租金价格"));
      }else if(value == 3 && this.form.sellMode == 3){
        callback(new Error("出租和出售至少选择其一"));
      }
      callback();
    };
    var checkSellMode = (rule, value, callback) => {
      // if ((value == 1 && this.form.sellingPrice == "") && (this.form.rentMode == 1 && this.form.rentPrice == "")) {
      //   callback(new Error("请输入租金价格或出售价格"));
      // }
      if(!value){
        callback(new Error("请选择出售价格方式"));
      }else if(value == 3 && this.form.rentMode == 3){
        callback(new Error("出租和出售至少选择其一"));
      }else if (value == 1 && this.form.sellingPrice == "") {
        this.$refs.form.validateField("rentMode")
        callback(new Error("请输入出售价格"));
      }
      callback();
    };
    var checkFloorType = (rule, value, callback) => {
      if (this.form.floorType === "") {
        return callback(new Error("请选择楼层"));
      } else if (this.form.floorType == 1 && !this.form.buildingFloor) {
        callback(new Error("请输入楼层"));
      } else if (
        (this.form.floorType == 2 || this.form.floorType == 3) &&
        (!this.form.aboveGroundFloors ||
          !this.form.undergroundFloors ||
          !this.form.buildingHeight)
      ) {
        callback(new Error("请输入完整楼层信息"));
      } else {
        callback();
      }
    };
    var checkAgree = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请勾选楼宇企业入驻协议"));
      } else {
        callback();
      }
    };
    var checkRentalArea = (rule, value, callback) => {
      if (((this.form.rentalArea + '').indexOf('.') == -1 && (this.form.rentalArea + '').length >= 10) || 
          ((this.form.rentalArea + '').indexOf('.') == 10 && (this.form.rentalArea + '').length == 11)
      ) {
        callback(new Error("请输入[0-999999999]区间内的数值，小数点保留1位。"));
      } else {
        callback();
      }
    };
    var checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请输入联系方式"));
      } else {
        const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$|^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的手机号"));
        }
      }
    };
    var checkAppealName = (rule, value, callback) => {
      if (
        Number(this.form.recommendedStationMinimum) >
        Number(this.form.recommendedStationMaximum)
      ) {
        return callback(new Error("开始工位数应小于结束工位数"));
      }
      callback();
    };
    return {
      form: {
        airport:"" , // 机场
        highSpeedRail:"", // 高铁
        hospital:"", // 医院
        hydropowerPrice:"", //水电价格
        propertyFee:"", // 物业费
        propertyPriceUnit:1, // 物业费价格单位
        sellMode:"", // 出售类型
        sellingPrice:"", // 出售金额
        buildingName: "",
        buildingType: "",
        buildingLeave: "",
        canRegister: "",
        industryType: "",
        streetCode: "",
        address: "",
        buildingDecorationType: "",
        floorType: "",
        aboveGroundFloors: "", //地上多少层
        undergroundFloors: "", // 地下多少层
        buildingHeight: "", //楼高
        buildingFloor: "", //层
        rentMode: "", //租金方式 。。
        rentUnitMeasure: 1, //租金类型 。。
        rentPrice: "", //租金价格
        rentalArea: "", //出租面积
        rentTermMinimum: "", // 起租日期
        recommendedStationMinimum: "", // 推荐工位数
        recommendedStationMaximum: "", // 推荐工位数
        buildingIntroduce: "", //楼宇介绍
        restaurantNum: "", //周边餐厅数
        busStation: "", //  公交站
        apartments: "", //公寓数
        subwayStation: "", // 地铁站
        businessDistrict: "", //商圈
        settledEnterpriseInformation: "", //入驻企业信息
        highTechEnterprisesNum: "", //高薪企业数
        listedEnterprisesNum: "", //上市企业数
        biomedicalEnterpriseNum: "", //生物医药企业数
        propertyCompany: "", //楼宇物业公司
        propertyCompanyIntroduce: "", //物业公司介绍
        buildingVideo: "", // 楼宇视频文件批次id
        buildingImages: "", //	楼宇图片文件批次id
        videoCover: "", //视频封面
        contactsPerson: "", //联系人
        contactsPhone: "", // 联系电话
        readChecked: false, //同意协议
      },
      rules: {
        buildingName: [
          { required: true, message: "请输入楼宇名称", trigger: "blur" }
        ],
        businessDistrict: [
          { required: true, message: "请选择附近商圈名称", trigger: "change" }
        ],
        buildingType: [
          { required: true, message: "请选择楼宇类型", trigger: "change" }
        ],
        buildingLeave: [
          { required: true, message: "请选择楼宇级别", trigger: "change" }
        ],
        canRegister: [
          { required: true, message: "请选择是否可注册", trigger: "change" }
        ],
        streetCode: [
          { required: true, message: "请选择楼宇所在街道", trigger: "change" }
        ],
        address: [
          { required: true, message: "请输入详细位置", trigger: "blur" }
        ],
        buildingDecorationType: [
          { required: true, message: "请选择装修情况", trigger: "change" }
        ],
        floorType: [
          { required: true, message: "请选择楼层", trigger: "change" }
        ],
        rentMode: [
          { required: true, validator: checkRentMode, trigger: ["change", "blur"] },
        ],
        sellMode: [
          { required: true, validator: checkSellMode, trigger: ["change", "blur"] },
        ],
        floorType: [
          { required: true, validator: checkFloorType, trigger: "change" }
        ],
        rentalArea: [
          { required: true, message: "请输入出租面积", trigger: "blur" },
          { validator: checkRentalArea, trigger: "blur" }
        ],
        appealName: [
          { validator: checkAppealName, trigger: "blur" }
        ],
        rentTermMinimum: [
          { required: true, message: "请输入起租期", trigger: "blur" }
        ],
        propertyFee: [
          { required: true, message: "请输入物业费", trigger: "blur" }
        ],
        buildingIntroduce: [
          { required: true, message: "请输入楼宇介绍", trigger: "blur" }
        ],
        propertyCompany: [
          { required: true, message: "请输入物业公司名称", trigger: "blur" }
        ],
        propertyCompanyIntroduce: [
          { required: true, message: "请输入物业公司介绍", trigger: "blur" }
        ],
        buildingImages: [
          { required: true, message: "请上传楼宇图片", trigger: "change" }
        ],
        contactsPerson: [
          { required: true, message: "请输入联系人", trigger: "blur" }
        ],
        contactsPhone: [
          { required: true, validator: checkPhone, trigger: "blur" }
        ],
        readChecked: [
          { validator: checkAgree, trigger: "change" }
        ],
      }
    }
  }
}